package com.joshluisaac;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class ParseURL {

	/**
	 * @param args
	 * @throws MalformedURLException
	 */
	public static void main(String[] args) {

		try {
			URL url = new URL("http://0.0.0.0:9090/");
			// InputStream inStream = url.openConnection().getInputStream();
			InputStream inStream = url.openStream(); // shorthand version for
														// openConnection().getInputStream()
			URLConnection urlConnection = url.openConnection();

			/*
			 * urlConnection.connect(); is unnecessary since url.openStream();
			 * which returns an InputStream object will implicitly do the
			 * connection
			 */

			InputStreamReader inStreamReader = new InputStreamReader(urlConnection.getInputStream());

			/*
			 * InputStreamReader inStreamReader = new
			 * InputStreamReader(urlConnection.getInputStream()); new
			 * InputStreamReader(inStream); and new
			 * InputStreamReader(urlConnection.getInputStream()); are same
			 * because they both return a stream which is an InputStream object
			 */

			BufferedReader bufferedReader = new BufferedReader(inStreamReader);
			String inputLine = null;
			while ((inputLine = bufferedReader.readLine()) != null) {
				System.out.println(inputLine);
			}
			bufferedReader.close();
		}

		catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
